function _mergeSort(arr, l, r) {
    if(l === r) return
    let mid = (l + r) >>> 1
    _mergeSort(arr, l, mid)
    _mergeSort(arr, mid + 1, r)
    let l1 = l, r1 = mid
    let l2 = mid + 1, r2 = r
    let index = l
    while(l1 <= r1 && l2 <= r2) {
        if(arr[l1] < arr[l2]) {
            temp[index++] = arr[l1++]
        } else {
            temp[index++] = arr[l2++]
        }
    }
    while(l1 <= r1) {
        temp[index++] = arr[l1++]
    }
    while(l2 <= r2) {
        temp[index++] = arr[l2++]
    }
    for(let i = l; i <= r; i++) {
        arr[i] = temp[i]
    }
}
let arr = [9, 8, 6, 2, 5, 1, 1, 10]
let temp = new Array(arr.length)
_mergeSort(arr, 0, arr.length - 1)
console.log(arr);